package com.lukk.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpSession;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.stereotype.Service;
import com.lukk.dao.GoodDAO;
import com.lukk.dao.GoodSpecialDAO;
import com.lukk.pojo.Good;
import com.lukk.pojo.GoodSpecial;
import com.lukk.service.IGoodService;
import com.lukk.util.JsonUtil;

/**
 * 
 * GoodServiceImpl 上午11:45:28 Copyright zhaocj Inc. All Rights reserved.
 * alldios@outlook.com
 *
 */
@Service("goodService")
public class GoodServiceImpl implements IGoodService {
	private static Logger logger = LogManager.getLogger(GoodServiceImpl.class.getName());
	@Resource
	private GoodDAO goodDAO;
	@Resource
	private GoodSpecialDAO goodSpecialDAO;

	@Override
	public Map<String, Object> selectIndentProductGoodPartsByIndent(Integer offset, Integer limit, String sort,
			String order, Integer indentID, HttpSession session) {
		logger.debug("你好 开始调用本方法");
		Map<String, Object> retMap = new HashMap<String, Object>();
		// 查看该订单的成品帘商品 查询基础信息
		List<Good> goods = goodDAO.selectIndentGoodByIndent(indentID, 1);
		logger.debug("查出的成品链商品有：{}", JsonUtil.toJson(goods));
		List<GoodSpecial> goodSpecials = new ArrayList<GoodSpecial>();
		for (Good good : goods) {
			// 根据good查询出配件信息
			goodSpecials.addAll(goodSpecialDAO.selectGoodSpecialsByGood(good.getGoodsId()));
		}
		retMap.put("productGoodPart", goodSpecials);
		return retMap;
	}

	@Override
	public Map<String, Object> selectIndentClothGoodPartsByIndent(Integer offset, Integer limit, String sort,
			String order, Integer indentID, HttpSession session) {
		Map<String, Object> retMap = new HashMap<String, Object>();
		List<Good> goods = goodDAO.selectIndentGoodByIndent(indentID, 0);
		logger.debug("查出的布艺帘商品有：{}", JsonUtil.toJson(goods));
		List<GoodSpecial> goodSpecials = new ArrayList<GoodSpecial>();
		for (Good good : goods) {
			goodSpecials.addAll(goodSpecialDAO.selectGoodSpecialsByGood(good.getGoodsId()));
		}
		retMap.put("clothGoodPart", goodSpecials);
		return retMap;
	}

}
